<?php
class Config extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	function val($key)
	{
		$this->db->select('value');
		$query = $this->db->get_where('config', array('name'	=>$key));
		if($query->num_rows==0) return false;
		$result = $query->row_array();
		return $result['value'];
	}
	function create($data)
	{
		$this->db->insert('config',$data);
	}
	function update($data)
	{
		$this->db->update('config',$data,array('name'	=> $data['name']));
	}
	function get_all()
	{
		$this->db->select('*');
		$this->db->order_by('description','asc');
		$query = $this->db->get_where('config');
		return $query->result_array();
	}
	function update_all($data)
	{
		foreach($data as $name => $value)
		{
			$row['name'] = $name;
			$row['value']=$value;
			$this->update($row);
		}
	}
}